#include "sentry.h"
#include <QtGui/QApplication>

int main(int argc, char *argv[])
{
	int X = 0;
	int Y = 0;
	//CommandMenu menu;
	BlobDetector blob;
	blob.LastTransX = 0;
	blob.LastTransY = 0;
	VideoCapture Cam(1);
	Cam >> blob.Frame;

	Communicator Comm;
	cout << "Setting up communication module" << endl;
	Comm.Setup();
	cout << "Communication module running" << endl;

	//Needs to wait for the Arduino to give it time to setup the serial connection.
	Sleep(3000);
	QApplication a(argc, argv);
	Sentry w;
	w.show();

	
	while(true)
	{
		blob.LoadLiveFeed(Cam);
		blob.Image_Scan();
		cout << "Enter x angle: ";
		cin >> X;
		cout << endl;
		cout << "Enter y angle: "; 
		cin >> Y;
		cout << endl;

		if ((blob.LastMassCol != blob.LastTransX) || (blob.LastMassRow != blob.LastTransY))
		{
			//X++;
		    //Y++;
			Comm.Send(blob.LastMassCol, blob.LastMassRow, X, Y);

			cout << "Send: " << blob.LastMassRow << ' ' <<blob.LastMassCol << ' ' << Y << ' ' << X<< ' ' << endl;
			blob.LastTransX = blob.LastMassCol;
			blob.LastTransY = blob.LastMassRow;
		
			Comm.Recieve();

			cout << "Recv: " << Comm.RecvData.Struc.Y << ' ' << Comm.RecvData.Struc.X << ' ' << Y << ' ' << X << ' ' << endl;
			cout << endl;
		}
		cvWaitKey(1);
	};

	return a.exec();
}
